package com.base.study.adapter;

import android.text.Html;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.base.commonlib.http.RealNetWorkUtil;
import com.base.commonlib.recy.BasicRecyViewHolder;
import com.base.commonlib.recy.HFSingleTypeRecyAdapter;
import com.base.commonlib.utils.GlideUtil;
import com.base.commonlib.utils.SubStringUtil;
import com.base.study.R;
import com.base.study.bean.EsSearchResultBean;
import com.base.study.bean.SearchResultBean;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * 在此写用途
 *
 * @version V1.0 <描述当前版本功能>
 *          Created by admin on 2018/5/22.
 * @FileName: com.zhongyue.mdchengguan.ui.main.adapter.CategoryAdapter.java
 * Author weikailiang
 * @date: 2018-05-22 17:31
 */
public class PopualSearchAdapter extends HFSingleTypeRecyAdapter<SearchResultBean,PopualSearchAdapter.RecyViewHolder> {


    public PopualSearchAdapter(int resId) {
        super(resId);
    }

    @Override
    public RecyViewHolder buildViewHolder(View itemView) {
        return new RecyViewHolder(itemView);
    }

    @Override
    public void bindDataToHolder(RecyViewHolder holder, SearchResultBean searchResultBean, int position) {
        //                if (!TextUtils.isEmpty(item.get())) {
        GlideUtil.load_nocatch(holder.course_photo.getContext(), searchResultBean.getUrl(), holder.course_photo);
//                }
        holder.course_photo.setVisibility(View.GONE);
        //holder.course_state.setText(searchResultBean.getName());
      //  holder.course_intro.setText(SubStringUtil.subStringCN(searchResultBean.getFlfg_captions(),200));
        holder.course_title.setText(searchResultBean.getName());
        holder.course_time.setText(searchResultBean.getCreateDate());
       // holder.course_time.setText(formatDate(searchResultBean.getFlfg_pubdata()));
    }


    public static class RecyViewHolder extends BasicRecyViewHolder {
        TextView course_state;
        TextView course_title;
        TextView course_intro;
        TextView course_time;
        ImageView course_photo;
        public RecyViewHolder(View itemView) {
            super(itemView);
            course_state = itemView.findViewById(R.id.course_state);
            course_title = itemView.findViewById(R.id.course_title);
            course_intro = itemView.findViewById(R.id.course_intro);
            course_time = itemView.findViewById(R.id.course_time);
            course_photo = itemView.findViewById(R.id.course_photo);
        }
    }


    public String formatDate(String inputDate){
        try{
            DateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
            DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX", Locale.US);
            Date date = inputFormat.parse(inputDate);
            return outputFormat.format(date);
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
}
